<?php get_instance()->view('common/header');?>
<body>
<div class="content">
    <form action="<?php echo getUrl('user/saveAddress')?>" id="save-form" method="post">
        <div class="weui-cells mb20">
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd">
                    <span style="vertical-align: middle" class="f08">收货人</span>
                </div>
                <div class="f08"><input class="weui-input listrightinput" type="text" placeholder="请输入收货人姓名" name="consignee" value="<?php echo !$add ? $info['consignee'] : ''?>"></div>
            </div>
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd vCenter">
                    <label class="vCenter mr20 f09"><input type="radio" name="gender" class="checkradio" <?php if ($add || (!$add && $info['gender'] == 1)):?> checked="checked" <?php endif;?> value="1" /><span class="icon-checked f12 mr5"></span>先生</label>
                    <label class="vCenter f09"><input type="radio" name="gender" class="checkradio" <?php if (!$add && $info['gender'] == 2):?> checked <?php endif;?> value="2" /><span class="icon-checked f12 mr5"></span>女士</label>
                </div>
            </div>
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd">
                    <span style="vertical-align: middle" class="f08">联系方式</span>
                </div>
                <div class="f08"><input class="weui-input listrightinput" type="text" placeholder="请输入收货人电话" name="mobile" value="<?php echo !$add ? $info['mobile'] : ''?>"></div>
            </div>
            <div class="weui-cell weui-cell_access ">
                <div class="weui-cell__bd">
                    <span class="hengleft vCenter f085">所属区域</span>
                </div>
                <div class="weui-cell__ft f08">
                    <input type="text" class="showDouble b0 tr" data-type="county_name" placeholder="请选择城市区域"
                           readonly value="<?php echo !$add ? $info['county_name'] : ''?>">
                    <input type="hidden" name="province" value="<?php echo !$add ? $info['province'] : ''?>">
                    <input type="hidden" name="city" value="<?php echo !$add ? $info['city'] : ''?>">
                    <input type="hidden" name="county" value="<?php echo !$add ? $info['county'] : ''?>">
<!--                    <input type="hidden" name="county_name" value="--><?php //echo !$add ? $info['county_name'] : ''?><!--">-->
                </div>
                <script type="text/javascript">
                    $(function () {
                        //2级联动
                        var data = JSON.parse('<?php echo $location?>');
                        var _picker, defaultValue;
                        <?php if (!$add):?>
                        defaultValue = ['<?php echo $info["province"]?>','<?php echo $info["city"]?>','<?php echo $info["county"]?>'];
                        <?php else:?>
                        defaultValue = ['3','3401','3402'];
                        <?php endif;?>
                        $('.showDouble').on('click', function () {
                            var name = $(this).attr('data-type');
                            _picker = $(this);
                            weui.picker(data, {
                                id:name,
                                defaultValue:defaultValue,
                                onChange: function (result) {
                                },
                                onConfirm: function (result) {
                                    var id = result[0]+','+result[1]+','+result[2];
                                    getAjax(id);
                                    $('[name="province"]').val(result[0]);
                                    $('[name="city"]').val(result[1]);
                                    $('[name="county"]').val(result[2]);
                                }
                            });
                        });

                        function getAjax(id) {
                            blockUI.show();
                            $.ajax('<?php echo getUrl('common/getAjaxAddress');?>', {
                                type:'post',
                                data:{address_id:id},
                                error:function(){
                                    blockUI.hide();
                                    show_message({status:0, message:'请求超时'});
                                },
                                timeout:60000,
                                success:function(e,textStatus,jqXHR){
                                    blockUI.hide();
                                    _picker.val(e);
//                                    $('[name="county_name"]').val(e);
                                }
                            });
                        }
                    })
                </script>
            </div>
            <div class="weui-cell weui-cell_access ">
                <div class="weui-cell__bd">
                    <span style="vertical-align: middle" class="f08">导航地址</span>
                </div>
                <div class="f08">
                    <input class="weui-input listrightinput address" type="text" placeholder="请填写详细地址" readonly
                           value="<?php echo !$add ? $info['address'] : ''?>">
                </div>
                <input type="hidden" value="<?php echo !$add ? $info['address'] : ''?>" name="address">
                <input type="hidden" value="<?php echo !$add ? $info['latitude'] : ''?>" name="latitude">
                <input type="hidden" value="<?php echo !$add ? $info['longitude'] : ''?>" name="longitude">
                <input type="hidden" value="<?php echo $lat ?>" name="lat">
                <input type="hidden" value="<?php echo $lng ?>" name="lng">
            </div>
            <div class="weui-cell weui-cell_access">
                <div class="weui-cell__bd">
                    <span style="vertical-align: middle" class="f08">详细地址</span>
                </div>
                <div class="f08"><input class="weui-input listrightinput" type="text" placeholder="请填写街道、门牌号等" name="street" value="<?php echo !$add ? $info['street'] : ''?>"></div>
            </div>
        </div>
        <input type="hidden" name="address_id" value="<?php echo !$add ? $info['id'] : 0?>">
        <button class="kbtn">确认提交</button>
    </form>
    <script type="text/javascript">
        $(function () {
            $.e_validate.init('#save-form',{saveMessage:'保存中...'});
        })
    </script>
</div>
<?php get_instance()->view('common/map');?>
</body>
<script src="<?php echo $this->staticUrl?>js/base.js"></script>
<script type="text/javascript">
    $(function () {
        // 显示地图
        $(".address").click(function () {
            $(".map_div").show();
            $(".content").hide();
        });
    })
</script>
</html>